<?php
/**
 * Created by PhpStorm.
 * User: yiyu
 * Email: smalleasyu@gmail.com
 * Date: 2020-01-22 12:55:56
 * Desc: 发送微信公众号消息
 */

namespace app\base\service\WeChat;

use app\base\service\BaseService;
use EasyWeChat\Kernel\Messages\Text;
use EasyWeChat\Kernel\Messages\Image;
use EasyWeChat\Kernel\Messages\Video;
use EasyWeChat\Kernel\Messages\Voice;
use EasyWeChat\Kernel\Messages\News;
use EasyWeChat\Kernel\Messages\Link;
use EasyWeChat\Kernel\Messages\Location;
use EasyWeChat\Kernel\Messages\NewsItem;
use EasyWeChat\Kernel\Messages\Article;
use EasyWeChat\Kernel\Messages\Media;
use EasyWeChat\Kernel\Messages\Raw;

class SendMessage extends BaseService
{
    public static function sendTextMsg($msg)
    {
        return new Text($msg);
    }

    public static function sendImageMsg($mediaId)
    {
        return new Image($mediaId);
    }

    /**
     * Desc:
     * Date: 2020/1/22 0:59
     * Author: yiyu
     * @param $mediaId string 媒体资源 ID
     * @param $title string 标题
     * @param $description string 描述
     * @param $thumb_media_id string 封面资源 ID
     * @return Video
     */
    public static function sendVideoMsg($mediaId, $title, $description, $thumb_media_id)
    {
        return new Video($mediaId, [
            'title' => $title,
            'description' => $description,
            'thumb_media_id' => $thumb_media_id,
        ]);
    }

    public static function sendVoiceMsg($mediaId)
    {
        return new Voice($mediaId);
    }

    public static function sendLinkMsg($msg)
    {
        return new Text($msg);//微信目前不支持回复链接消息
    }

    public static function sendLocationMsg($msg)
    {
        return new Text($msg);//微信目前不支持回复坐标消息
    }

    /**
     * Desc: 发送图文消息
     * Date: 2020/1/22 9:47
     * Author: yiyu
     * @param $title
     * @param $description
     * @param $url
     * @param $image
     * @return News
     */
    public static function sendNewsMsg($title, $description, $url, $image)
    {
        $items = [
            new NewsItem([
                'title' => $title,
                'description' => '...',
                'url' => $url,
                'image' => $image,
            ]),
        ];
        return new News($items);
    }

    /**
     * Desc:
     * Date: 2020/1/22 9:52
     * Author: yiyu
     * @param $title string 标题
     * @param $author string 作者
     * @param $content string 具体内容
     * @param $thumb_media_id string 图文消息的封面图片素材id（必须是永久mediaID）
     * @param $digest string 图文消息的摘要，仅有单图文消息才有摘要，多图文此处为空
     * @param $source_url string 来源 URL
     * @param $show_cover string 是否显示封面，0 为 false，即不显示，1 为 true，即显示
     * @return Article
     */
    public static function sendArticleMessage(
        $title,
        $author,
        $content,
        $thumb_media_id,
        $digest,
        $source_url,
        $show_cover
    ) {
        return new Article([
            'title' => $title,
            'author' => $author,
            'content' => $content,
            'thumb_media_id' => $thumb_media_id,
            'digest' => $digest,
            'source_url' => $source_url,
            'show_cover' => $show_cover,
        ]);
    }


    /**
     * Desc: 发送素材消息  素材消息用于群发与客服消息时使用 素材消息不支持被动回复，如需被动回复素材消息，首先组装后，再 News 方法返回
     * Date: 2020/1/22 10:14
     * Author: yiyu
     * @param $mediaId string 素材 ID，从接口查询或者上传后得到
     * @param $type string 素材类型，目前只支持：`mpnews`、 `mpvideo`、`voice`、`image` 等
     * @return Media
     */
    public static function sendMediaMessage($mediaId, $type)
    {
        return new Media($mediaId, $type);
    }


    /**
     * Desc: 发送原始消息
     * Date: 2020/1/22 10:31
     * Author: yiyu
     * @param $message_content string 消息结构体
     * @return Raw
     */
    public static function sendRawMessage($message_content)
    {
        return new Raw($message_content);
    }
}